package com.lx.entity;

import com.lx.annotation.Note;

import java.io.Serializable;
import java.util.concurrent.TimeUnit;

public class JwtInfo implements Serializable {
    private UserInfo userInfo;
    private long exp;

    public JwtInfo() {

    }
    public JwtInfo(UserInfo userInfo, TimeUnit timeUnit, long time) {
        this.userInfo = userInfo;
        this.exp = calcExp(timeUnit,time);
    }

    public UserInfo getUserInfo() {
        return userInfo;
    }

    public void setUserInfo(UserInfo userInfo) {
        this.userInfo = userInfo;
    }

    public long getExp() {
        return exp;
    }

    public void setExp(long exp) {
        this.exp = exp;
    }

    @Note("计算超时时间")
    public long calcExp(TimeUnit timeUnit, long time){
        return System.currentTimeMillis()+timeUnit.toMillis(time);
    }

    @Note("token是否过期")
    public boolean expired(){
        return System.currentTimeMillis() > exp;
    }

    @Override
    public String toString() {
        return "JwtInfo{" +
                "userInfo=" + userInfo +
                ", exp=" + exp +
                '}';
    }
}
